{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1e41f7b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import d2l\n",
    "import numpy as np\n",
    "\n",
    "def dropout(X, drop_prob):\n",
    "    assert 0<=drop_prob<=1\n",
    "    keep_prob = 1 - drop_prob\n",
    "    if keep_prob==0:\n",
    "        return X.zeros_like()\n",
    "    mask = np.random.uniform(0, 1, X.shape) < keep_prob\n",
    "    return mask * X / keep_prob\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56cbe5f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Xavier的参数初始化主要考虑到，模型参数初始化后，每层输出的方差不应该收到\n",
    "# 该层输入个数的影响，且每层梯度的方差也不该受该层输出个数的影响"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
